'use strict';

/**
 * @ngdoc function
 * @name magisterkaGuiApp.controller:CreateEventCtrl
 * @description
 * # CreateEventCtrl
 * Controller of the magisterkaGuiApp
 */
angular.module('magisterkaGuiApp')
    .controller('CreateEventCtrl', function ($scope, $log, $q, $http) {
        $scope.event = {url: 'https://www.facebook.com/AGH.Krakow/posts/10153039731360662'};

        $scope.event.visualisation='ALGORITHM_TOURNAMENT';

        var mockResponse = {token: 'NFJIAsBHNAfbguas'};

        var createEventMock = function (id) {
            return $q.when(mockResponse);
        };
        var createEventServer = function (id) {

            return $http.post(BASE_WEBSERVICE_URL + '/facebook/create_event', {
                    postId: id,
                    algorithm: $scope.event.visualisation
                }
            )
                ;
        };

        var eventCreatorRequest = createEventServer;


        function createEvent(url) {
            //var ids = url.match(/\Wid=(\w+)/);
            var id = '10153039731360662';
            $log.info(id);
            return eventCreatorRequest(id);
        }

        $scope.createEvent = function () {
            createEvent($scope.event.url).then(function (response) {
                $scope.eventResponse = response.data.token;
            });
        };

        $scope.fireEvent = function () {
            return $http.post(BASE_WEBSERVICE_URL + '/facebook/fire_event', {token: $scope.eventResponse}).then(function (response) {
                $log.info('Fire event response: ', response);
            });
        };

    })
;
